package repository

import (
	"context"

	"gitee.com/thewalkers/refactoring-code/model"
	"github.com/jmoiron/sqlx"
	"go.uber.org/zap"
)

// MysqlHourlyClassificationRepository is data/repository implementation
// of service layer EmployeeRepository
type MysqlHourlyClassificationRepository struct {
	DB *sqlx.DB
}

// NewHourlyClassificationRepository is a factory for initializing Employee Repository
func NewHourlyClassificationRepository(db *sqlx.DB) model.ChangeHourlyTransactionRepository {
	return &MysqlHourlyClassificationRepository{
		DB: db,
	}
}

func (m *MysqlHourlyClassificationRepository) Update(ctx context.Context, h *model.HourClassification) error {
	query := `UPDATE hour_classification SET rate = ? WHERE payment_classification_id = ?`
	if _, err := m.DB.Exec(query, h.Rate, h.PaymentClassificationID); err != nil {
		zap.L().Error("repository cound not update hourly classification with err: ", zap.Error(err))
		return err
	}

	return nil
}
